import { _decorator, Component, Button } from 'cc';
import RowFallClear_StartPanel from "./RowFallClear_StartPanel";
import RowFallClear_GameManager, { GameState } from '../Manager/RowFallClear_GameManager';
// import RowFallClear_GameManager, { GameState } from "../Manager/GameManager";

const { ccclass, property } = _decorator;

export enum SettingPanelType {
    setting,
    pause,
}

@ccclass('RowFallClear_SettingPanel')
export default class RowFallClear_SettingPanel extends Component {
    public static Instance: RowFallClear_SettingPanel;
    @property(Button)
    Button_close: Button | null = null;
    @property(Button)
    Button_mainmenu: Button | null = null;
    @property(Button)
    Button_continue: Button | null = null;
    @property(Button)
    Button_replay: Button | null = null;
    settingPanelType: SettingPanelType;
    onLoad() {
        RowFallClear_SettingPanel.Instance = this;
    }
    start() {
        this.Button_close.node.on('click', this.click_close, this);
        this.Button_mainmenu.node.on('click', this.click_main, this);
        this.Button_continue.node.on('click', this.click_continue, this);
        this.Button_replay.node.on('click', this.click_replay, this);
    }
    ShowOn(_settingPanelTyep: SettingPanelType) {
        this.settingPanelType = _settingPanelTyep;
        this.node.active = true;
        this.Refresh();
    }
    ShowOff() {
        this.node.active = false;

        if (this.settingPanelType = SettingPanelType.pause) {
            RowFallClear_GameManager.Instance.gameState = GameState.Free;
        }
    }
    Refresh() {
        this.Button_mainmenu.node.active = this.settingPanelType == SettingPanelType.pause;
        this.Button_continue.node.active = this.settingPanelType == SettingPanelType.pause;
        this.Button_replay.node.active = this.settingPanelType == SettingPanelType.pause;

    }
    click_close(button) {
        this.ShowOff();
    }
    click_main(button) {
        this.ShowOff();
        RowFallClear_GameManager.Instance.GameOver();
        RowFallClear_StartPanel.Instance.ShowOn();
    }
    click_continue(button) {
        this.ShowOff();
    }
    click_replay(button) {
        this.ShowOff();
        RowFallClear_GameManager.Instance.GameStart();
    }
}